package com.test.utils;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * Created by Lenovo on 2019/1/10.
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    private String[] encryptPropNames = {"jdbc_username", "jdbc_password"};
    @Override
    protected String convertProperty(String propertyName, String propertyValue) {
        if(isEncryptProp(propertyName)){
            propertyValue = DESUtil.getDecryptString(propertyValue);
            return propertyValue;
        }
        return propertyValue;
    }

    private boolean isEncryptProp(String propertyName) {
        for(String encrypropertyName : encryptPropNames){
            if(propertyName.equals(encrypropertyName)){
                return true;
            }
        }
        return false;
    }
}
